
#include "Logger.h"
#include <iostream>

int main()
{
    std::cout << "=== 完整日志系统测试 ===" << std::endl; // 设置日志级别
    Logger::getInstance().SetLogLevel(Logger::FATAL);

    // 设置日志文件最大大小（1KB，便于测试轮转）
    Logger::getInstance().SetMaxFileSize(1024);

    // 设置日志文件路径
    Logger::getInstance().SetLogPath("./logs/");

    std::cout << "1. 基本日志测试..." << std::endl;

    // 基本日志测试
    LOGD("Debug message: %s %d", "test", 123);
    LOGI("Info message: Application started successfully");
    LOGW("Warning message: This is a warning with number %d", 456);
    LOGE("Error message: Something went wrong");
    LOGF("Fatal message: Critical error occurred");

    std::cout << "2. 多线程日志测试..." << std::endl;

    // 多线程日志测试
    std::vector<std::thread> threads;

    // 创建多个线程同时写日志
    for (int i = 0; i < 3; ++i)
    {
        threads.emplace_back([i]()
                             {
        for (int j = 0; j < 50; ++j) {
            LOGI("Thread %d: message %d", i, j);
            LOGW("Thread %d: warning %d", i, j);
            
            if (j % 10 == 0) {
                LOGE("Thread %d: error at iteration %d", i, j);
            }
            
            // 模拟一些工作
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
        } });
    }

    // 等待所有线程完成
    for (auto &t : threads)
    {
        t.join();
    }

    std::cout << "3. 日志级别过滤测试..." << std::endl;

    // 测试不同日志级别
    Logger::getInstance().SetLogLevel(Logger::WARN);

    LOGD("This debug message should NOT appear");
    LOGI("This info message should NOT appear");
    LOGW("This warning message SHOULD appear");
    LOGE("This error message SHOULD appear");

    // 恢复调试级别
    Logger::getInstance().SetLogLevel(Logger::DEBUG);
    LOGI("Log level restored to DEBUG");

    std::cout << "4. 文件轮转测试..." << std::endl;

    // 生成足够多的日志来触发文件轮转
    for (int i = 0; i < 100; ++i)
    {
        LOGD("File rotation test message %d - This is a longer message to fill up the log file faster", i);
        LOGI("File rotation test message %d - This is a longer message to fill up the log file faster", i);
        LOGE("File rotation test message %d - This is a longer message to fill up the log file faster", i);
        LOGW("File rotation test message %d - This is a longer message to fill up the log file faster", i);
    }

    // 让程序运行一段时间，确保所有日志都被写入
    std::this_thread::sleep_for(std::chrono::seconds(3));

    std::cout << "5. 测试完成！" << std::endl;
    std::cout << "请检查 ./logs/ 目录中的日志文件" << std::endl;

    // 手动停止日志系统（可选，析构函数会自动调用）
    Logger::getInstance().Stop();

    return 0;
}